package com.haois.mp.wechat.util;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpService;
import com.haois.mp.database.module.basic.util.SpringContextHolder;
import org.springframework.stereotype.Component;

/**
 * Created by RuiHaoZ on 2018/3/24 23:02
 */
@Component
public class WxUtil {

    private static String baseUrl = "";

    /**
     * @param wxMpService
     * @param url mappingUrl
     * @param key urlKey
     * @param baseUrl 项目Url
     * @return
     */
    public static String transferWxUrl(WxMpService wxMpService, String url, String key, String baseUrl) {
        url = wxMpService.oauth2buildAuthorizationUrl(baseUrl + url,
                WxConsts.OAuth2Scope.SNSAPI_BASE, key);
        return url;
    }

    /**
     * @param url mappingUrl
     * @param key urlKey
     * @param baseUrl 项目Url
     * @return
     */
    public static String transferWxUrl(String url, String key, String baseUrl) {
        WxMpService wxMpService = SpringContextHolder.getBean(WxMpService.class);
        return transferWxUrl(wxMpService, url, key, baseUrl);
    }
}
